<?php if (!defined('TL_ROOT')) die('You cannot access this file directly!');

/**
 * Contao Open Source CMS
 * Copyright (C) 2005-2011 Leo Feyer
 *
 * Formerly known as TYPOlight Open Source CMS.
 *
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program. If not, please visit the Free
 * Software Foundation website at <http://www.gnu.org/licenses/>.
 *
 * PHP version 5
 * @copyright  2012 Andreas Koob 
 * @author     Andreas Koob 
 * @package    piwik_analyser 
 * @license    LGPL 
 * @filesource
 */


/**
 * Class piwik_analyser_module_visitssummary
 *
 * @copyright  2012 Andreas Koob 
 * @author     Andreas Koob 
 * @package    Controller
 */
class piwik_analyser_module_visitssummary extends frontend
{
	private $functions;
	
	public function __construct()
	{
		$this->import('Database');
		$this->import('Input');
		$this->functions = new piwik_analyser_functions();
	}
	
	public function getFunctions($currentFunction)
	{
		$strFunctions='';
		$strFunctions.='<option value="visistssummary.get"';if($currentFunction=='visistssummary.get'){$strFunctions.=' selected="selected"';}$strFunctions.='>get</option>';
		$strFunctions.='<option value="visistssummary.getvisits"';if($currentFunction=='visistssummary.getvisits'){$strFunctions.=' selected="selected"';}$strFunctions.='>getVisits</option>';
		$strFunctions.='<option value="visistssummary.getuniquevisitors"';if($currentFunction=='visistssummary.getuniquevisitors'){$strFunctions.=' selected="selected"';}$strFunctions.='>getUniqueVisitors (Not implemented)</option>';
		$strFunctions.='<option value="visistssummary.getactions"';if($currentFunction=='visistssummary.getactions'){$strFunctions.=' selected="selected"';}$strFunctions.='>getActions (Not implemented)</option>';
		$strFunctions.='<option value="visistssummary.getmaxactions"';if($currentFunction=='visistssummary.getmaxactions'){$strFunctions.=' selected="selected"';}$strFunctions.='>getMaxActions (Not implemented)</option>';
		$strFunctions.='<option value="visistssummary.getbouncecount"';if($currentFunction=='visistssummary.getbouncecount'){$strFunctions.=' selected="selected"';}$strFunctions.='>getBounceCount (Not implemented)</option>';
		$strFunctions.='<option value="visistssummary.getvisitsconverted"';if($currentFunction=='visistssummary.getvisitsconverted'){$strFunctions.=' selected="selected"';}$strFunctions.='>getVisitsConverted (Not implemented)</option>';
		$strFunctions.='<option value="visistssummary.getsumvisitslength"';if($currentFunction=='visistssummary.getsumvisitslength'){$strFunctions.=' selected="selected"';}$strFunctions.='>getSumVisitsLength (Not implemented)</option>';
		$strFunctions.='<option value="visistssummary.getsumvisitslengthpretty"';if($currentFunction=='visistssummary.getsumvisitslengthpretty'){$strFunctions.=' selected="selected"';}$strFunctions.='>getSumVisitsLengthPretty (Not implemented)</option>';
		return $strFunctions;
	}
	
	public function getQueryCode($function)
	{
		switch($function)
		{
			case 'visistssummary.get':
				$strCode=$accounts=$this->functions->getAccountsCode($this->Input->post('account'));
				$strCode=$accounts=$this->functions->getSiteIdCode($this->Input->post('account'),$this->Input->post('siteid'));
				$strCode.=$this->functions->getPeriodCode($this->Input->post('period')) . '<br />';
				$strCode.='<legend>Date:</legend><input type="text" name="date" class="tl_text" value="' . $this->Input->post('date') . '" /><br />';
				$strCode.='<legend>Segment:</legend><input type="text" name="segment" class="tl_text" value="' . $this->Input->post('segment') . '" /><br />';
				$strCode.='<legend>Columns:</legend><input type="text" name="columns" class="tl_text" value="' . $this->Input->post('columns') . '" /><br />';
				return $strCode;
				break;
			case 'visistssummary.getvisits':
				$strCode=$accounts=$this->functions->getAccountsCode($this->Input->post('account'));
				$strCode.='<legend>SiteId:</legend><input type="text" name="siteid" class="tl_text" value="' . $this->Input->post('siteid') . '" /><br />';
				$strCode.=$this->functions->getPeriodCode($this->Input->post('period')) . '<br />';
				$strCode.='<legend>Date:</legend><input type="text" name="date" class="tl_text" value="' . $this->Input->post('date') . '" /><br />';
				$strCode.='<legend>Segment:</legend><input type="text" name="segment" class="tl_text" value="' . $this->Input->post('segment') . '" /><br />';
				return $strCode;
				break;
			case 'visistssummary.getuniquevisitors':
				break;
			case 'visistssummary.getactions':
				break;
			case 'visistssummary.getmaxactions':
				break;
			case 'visistssummary.getbouncecount':
				break;
			case 'visistssummary.getvisitsconverted':
				break;
			case 'api.getvisitecommercestatusfromid':
				break;
			case 'api.getvisitecommercestatus':
				break;
			case 'visistssummary.getsumvisitslength':
				break;
			case 'visistssummary.getsumvisitslengthpretty':
				break;
			default:
				break;
		}
	}
	
	public function processFunction($function)
	{
		
		switch($function)
		{
			case 'visistssummary.get':
				$account=$this->functions->getAccountDetails($this->Input->post('account'));
				$url=$account['url'];
				$url.='/?module=API';
				$url.='&method=VisitsSummary.get';
				$url.='&idSite=' . $this->Input->post('siteid');
				$url.='&period=' . $this->Input->post('period');
				$url.='&date=' . $this->Input->post('date');
				$url.='&columns=' . $this->Input->post('columns');
				$url.='&format=php';
				$url.='&token_auth=' . $account['token'];
				$fetched = file_get_contents($url);
				$arrResult=array(
					'query'=>$url,
					'result'=>unserialize($fetched)
				);
				return $arrResult;
				break;
			case 'visistssummary.getvisits':
				$account=$this->functions->getAccountDetails($this->Input->post('account'));
				$url=$account['url'];
				$url.='/?module=API';
				$url.='&method=VisitsSummary.getVisits';
				$url.='&idSite=' . $this->Input->post('siteid');
				$url.='&period=' . $this->Input->post('period');
				$url.='&date=' . $this->Input->post('date');
				$url.='&format=php';
				$url.='&token_auth=' . $account['token'];
				$fetched = file_get_contents($url);
				$arrResult=array(
					'query'=>$url,
					'result'=>unserialize($fetched)
				);
				return $arrResult;
				break;
			case 'visistssummary.getuniquevisitors':
				break;
			case 'visistssummary.getactions':
				break;
			case 'visistssummary.getmaxactions':
				break;
			case 'visistssummary.getbouncecount':
				break;
			case 'visistssummary.getvisitsconverted':
				break;
			case 'api.getvisitecommercestatusfromid':
				break;
			case 'api.getvisitecommercestatus':
				break;
			case 'visistssummary.getsumvisitslength':
				break;
			case 'visistssummary.getsumvisitslengthpretty':
				break;
			default:
				break;
		}
	}
}

?>